package com.jiawa.train.business.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jiawa.train.common.resp.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @SentinelResource(value = "hello", blockHandler = "myBlockHandler")
    @GetMapping("/hello")
    public Result hello() {
        return Result.success("hello world business");
    }

    // 降级方法
    public Result myBlockHandler(BlockException e) {
        return Result.error("请求太频繁，请稍后再试！");
    }
}
